
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout

# Create your views here.
def login_view(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            return redirect('user_manage')  # 登录成功后跳转到用户管理页面
        else:
            return render(request, 'login.html', {'error': '用户名或密码错误'})
    return render(request, 'login.html')

def user_manage(request):
    # 用户管理逻辑
    return render(request, 'user_manage.html')

def index(request):
    # 主页逻辑
    return render(request, 'index.html')

def device_management(request):
    # 设备管理逻辑
    return render(request, 'device_manage.html')

def messages(request):
    # 消息页面逻辑
    return render(request, 'messages.html')
